// 导入Vue
import Vue from 'vue'
// 导入Vuex
import Vuex from 'vuex'

// 导入账户模块
import account from './modules/account'
// 导入广告模块
import advertising from './modules/advertising'
// 导入课程模块
import course from './modules/course'
// 导入视频模块
import video from './modules/video'
// 评论模块
import comment from './modules/comment'

// 使用vuex 持久化插件 
import VuexPersistence from 'vuex-persist'

//引入 types
import * as types from './types'
// 使用vuex
Vue.use(Vuex)
// 设置存储源为localStorage
const vuexLocal = new VuexPersistence({
    storage: window.localStorage
})
export default new Vuex.Store({
    //加载模块
    modules: {
        account,
        advertising,
        course,
        video,
        comment
    },
    //公共state
    state: {
        isShowLoading: false,
    },
    //公共mutation
    mutations: {
        [types.SHOW_LOADING](state) {
            state.isShowLoading = true;
        },
        [types.HIDE_LOADING](state) {
            state.isShowLoading = false;
        }
    },
    plugins: [vuexLocal.plugin]
})
